package com.lanou.web.servlet;

import com.alibaba.fastjson.JSON;
import com.lanou.entity.Prize;
import com.lanou.service.PrizeService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/prize/list")
public class PrizeListServlet extends HttpServlet {

    private PrizeService prizeService = new PrizeService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,
            IOException {
        List<Prize> prizeList = prizeService.findAllPrize();
        String jsonString = JSON.toJSONString(prizeList);

        response.setContentType("application/json;charset=utf-8");
        response.getWriter().print(jsonString);
    }
}
